﻿namespace Sgr.Security.VerifyCode
{
    /// <summary>
    /// 验证码服务接口
    /// </summary>
    public interface IVerifyCodeService
    {
        /// <summary>
        /// 创建验证码
        /// </summary>
        /// <param name="receiverType">接收方式：Phone/Email</param>
        /// <param name="receiver">接收地址（手机号/邮箱）</param>
        /// <param name="purpose">用途</param>
        /// <param name="expireMinutes">过期时间（分钟）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>发送结果</returns>
        Task<string> CreateAsync(
            ReceiverType receiverType,
            string receiver,
            string purpose,
            int expireMinutes = 5,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证验证码
        /// </summary>
        /// <param name="receiverType">接收方式：Phone/Email</param>
        /// <param name="receiver">接收地址（手机号/邮箱）</param>
        /// <param name="purpose">用途</param>
        /// <param name="code">验证码</param>
        /// <param name="isTemporary">是否临时性的。如果是则不会立即清理验证码缓存状态；如果否则立即清理</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>验证结果</returns>
        Task<bool> VerifyAsync(
            ReceiverType receiverType,
            string receiver,
            string purpose,
            string code,
            bool isTemporary = false,
            CancellationToken cancellationToken = default);
    }

    public enum ReceiverType
    {
        Email,
        Phone
    }
}